package com.atguigu.boot;

import com.atguigu.boot.bean.Pet;
import com.atguigu.boot.bean.User;
import com.atguigu.boot.config.MyConfig;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.ConfigurableApplicationContext;

/**
 * @author anan
 * @create 2021-08-10 16:35
 */
//使用该注解表示这是一个SpirngBoot应用
@SpringBootApplication
public class MainApplication {
    public static void main(String[] args) {
        ConfigurableApplicationContext run = SpringApplication.run(MainApplication.class, args);
        String[] beanDefinitionNames = run.getBeanDefinitionNames();
        for (String beanDefinitionName : beanDefinitionNames) {
            System.out.println(beanDefinitionName);
        }
/*        Pet tom01 = run.getBean("tom01", Pet.class);
        Pet tom02 = run.getBean("tom01", Pet.class);
        Pet tom03 = run.getBean("tom01", Pet.class);
        System.out.println("组件：" + (tom01 == tom02));*/

        MyConfig bean = run.getBean(MyConfig.class);
        System.out.println(bean);

        System.out.println("======================");
        String[] beanNamesForType = run.getBeanNamesForType(User.class);
        for (String s : beanNamesForType) {
            System.out.println(s);
        }

        System.out.println("============================");
        boolean tom01 = run.containsBean("user01");
        System.out.println(tom01);
        boolean haha = run.containsBean("haha");
        System.out.println("容器中haha组件：" + haha);
        boolean hehe = run.containsBean("hehe");
        System.out.println("容器中hehe组件：" + hehe);


    }
}
